import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Proporciona el obstaculo de aceite para el mundo.
 * 
 * @author Asael Hernández García 
 * @version (a version number or a date)
 */
public class Aceite extends Obstaculos
{
    /**
     * Act - do whatever the Aceite wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private SimpleTimer timer;
    private GreenfootImage imagen;
    private GreenfootSound aceite;
    private int damage;
    
    public Aceite()
    {
        timer = new SimpleTimer();
        timer.mark();
        resetPixels();
        imagen = new GreenfootImage("Aceite.png");
        aceite = new GreenfootSound("aceite.wav");
        aceite.setVolume(80);
        setImage(imagen);
        damage = 5;
    }
    
    public void act() 
    {
        mover();
        if(isTouching(Jugador.class)){
            aceite.play();
            ((PistaAutomovil)getWorld()).addDamage(damage);
            damage = 0;
        }
        if(timer.millisElapsed() > 250) {
            if(getImage().getWidth() >= 15 && getImage().getHeight() >= 15)
                disminuyeTam(getImage().getWidth()-getPixels()-2, getImage().getHeight()-getPixels());  
            if(getY() <= getWorld().getHeight()/2 - getImage().getHeight()/2)    
                ((PistaAutomovil)getWorld()).removeObs(this);    
            timer.mark();
            addPixels();
        }    
    }
}